package com.pinda.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.pinda.base.entity.PdCourierScop;
import com.pinda.common.CustomIdGenerator;
import com.pinda.mapper.PdCourierScopMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pinda.service.IPdCourierScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import com.pinda.service.IPdCourierScopeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 快递员业务范围表 服务实现类
 * </p>
 *
 * @author lc
 * @since 2023-06-14
 */
@Service
public class PdCourierScopServiceImpl extends ServiceImpl<PdCourierScopMapper, PdCourierScop> implements IPdCourierScopeService {

    @Resource
    private  PdCourierScopMapper pdCourierScopMapper;
    @Override
    public void fanweisave(PdCourierScop pdCourierScop) {
        pdCourierScopMapper.fanweisave(pdCourierScop);
    }

    @Override
    public PdCourierScop fanweibanduan(PdCourierScop pdCourierScop) {
        return   pdCourierScopMapper.fanweibanduan(pdCourierScop);
    }

    @Override
    public void fanweiupdate(PdCourierScop pdCourierScop) {
        pdCourierScopMapper.fanweiupdate(pdCourierScop);
    }


    @Autowired
    private CustomIdGenerator idGenerator;

    @Override
    public void batchSave(List<PdCourierScop> scopeList) {
        scopeList.forEach(scope -> scope.setId(idGenerator.nextId(scope) + ""));
        saveBatch(scopeList);
    }

    @Override
    public void delete(String areaId, String userId) {
        LambdaQueryWrapper<PdCourierScop> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        boolean canExecute = false;
        if (StringUtils.isNotEmpty(areaId)) {
            lambdaQueryWrapper.eq(PdCourierScop::getAreaId, areaId);
            canExecute = true;
        }
        if (StringUtils.isNotEmpty(userId)) {
            lambdaQueryWrapper.eq(PdCourierScop::getUserId, userId);
            canExecute = true;
        }
        if (canExecute) {
            baseMapper.delete(lambdaQueryWrapper);
        }
    }

    @Override
    public List<PdCourierScop> findAll(String areaId, String userId) {
        LambdaQueryWrapper<PdCourierScop> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(areaId)) {
            lambdaQueryWrapper.eq(PdCourierScop::getAreaId, areaId);
        }
        if (StringUtils.isNotEmpty(userId)) {
            lambdaQueryWrapper.eq(PdCourierScop::getUserId, userId);
        }
        return baseMapper.selectList(lambdaQueryWrapper);
    }
}
